package ua.net.gm.server.walker;

import java.util.List;
import java.util.Map;

/**
 *
 * @author Yason
 */
public abstract class WalkerStrategy implements IWalkerStrategy
{
    private final IWalkerMovesFactory factory;
    
    private final IWalkerMovesEstimator estimator;

    public WalkerStrategy(IWalkerMovesFactory factory, IWalkerMovesEstimator estimator)
    {
        this.factory = factory;
        this.estimator = estimator;
    }

    @Override
    public IWalkerMove getMove(IWalker state)
    {
        IWalkerMove res = null;
        List<IWalkerMove> moves = factory.createMoves(state);
        if (moves != null)
        {
            Map<WalkerMoveRank, IWalkerMove> estimation = estimator.estimate(state, moves);
            if (estimation != null && !estimation.isEmpty())
            {
                res = this.chooseMove(state, estimation);
            }
        }
        return res;
    }
    
    protected abstract IWalkerMove chooseMove(IWalker state, Map<WalkerMoveRank, IWalkerMove> moves);
}
